from pydantic import BaseModel, Field, HttpUrl
from typing import Optional, List
from datetime import datetime

class OllamaModelInfo(BaseModel):
    """Ollama模型信息"""
    name: str
    modified_at: str
    size: int
    digest: str
    details: Optional[dict] = None

class OllamaModelListResponse(BaseModel):
    """Ollama模型列表响应"""
    models: List[OllamaModelInfo]

class ModelConfig(BaseModel):
    """模型配置"""
    llm_model: str = Field(..., description="LLM模型名称")
    embedding_model: str = Field(..., description="Embedding模型名称")
    ollama_base_url: str = Field(default="http://localhost:11434", description="Ollama服务地址")
    temperature: float = Field(default=0.7, ge=0.0, le=2.0, description="温度参数")
    max_tokens: int = Field(default=2000, ge=1, le=32000, description="最大token数")

class ModelConfigResponse(ModelConfig):
    """模型配置响应"""
    updated_at: Optional[datetime] = None
    
    class Config:
        from_attributes = True

class ConnectionTestResponse(BaseModel):
    """连接测试响应"""
    success: bool
    message: str
    ollama_version: Optional[str] = None
    available_models: Optional[List[str]] = None

